package com.hyjoy.util;

import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import java.util.Properties;

/**
 * Created by hyjoy on 2018/4/4.
 */
public class MailUtils {

    /**
     * @param email
     * @param emailMsg
     */
    public static void sendMail(String email, String emailMsg) {
        //  1.创建一个程序与邮件服务器会话对象 Session
        Properties properties = new Properties();
        properties.setProperty("mail.transport.protocol", "SMTP");
        // 设置发送邮件的服务器
        properties.setProperty("mail.host", "localhost");
        // 指定验证为true
        properties.setProperty("mail.smtp.auth", "true");
        // 创建验证器
        Authenticator authenticator = new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                // 设置发送人的账号密码
                return new PasswordAuthentication("admin", "123456");
            }
        };

        Session session = Session.getInstance(properties, authenticator);

        // TODO:
    }
}
